import org.apache.poi.hssf.usermodel.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;



//Puts file in database

public class ReadingFromExcelsheet 
{
    public  void UploadExcelSheet(String filename) throws Exception
    {
        
        
   InputStream inputStream = new FileInputStream(new File("C:\\Users\\Sanchit Garg\\Desktop\\Projects\\IVRSSystem\\"+filename));
   
    Workbook wb = WorkbookFactory.create(inputStream);
    Sheet sheet = wb.getSheetAt(0);
   
   

 Row row;
   // Cell cell;
    String[][] values=new String[sheet.getPhysicalNumberOfRows()-1][2];
     for(int i=1; i<sheet.getPhysicalNumberOfRows(); i++)
     {
         row=sheet.getRow(i);
         String s=row.getCell(0).toString();

         
         String roll=s.substring(0, 7);
         
         //System.out.println(roll);
       
         values[i-1][0]=roll;
        
         values[i-1][1]=row.getCell(1).toString();     
        }

    Database_access ob= new Database_access();
    
    String sp[]=filename.split("\\.");
    

    String tablename=sp[0];

    ob.InsertMarkSheet(values, tablename);

    }





}
